package logic

import (
	"baidu/modil/mysql"
	"context"

	"baidu/baidurpc/baidurpc"
	"baidu/baidurpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBookShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookShowLogic {
	return &BookShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BookShowLogic) BookShow(in *baidurpc.BookShowRequest) (*baidurpc.BookShowResponse, error) {
	// todo: add your logic here and delete this line
	var book mysql.Book
	mysql.DB.Debug().Where("id=?", in.BookId).Find(&book)

	return &baidurpc.BookShowResponse{
		Title:  book.Title,
		Text:   book.Text,
		UserId: book.UserId,
		Types:  book.Types,
		Likes:  int64(book.Likes),
		Author: book.Author,
	}, nil
}
